//
//  ViewController.m
//  KVO
//
//  Created by 徐凯 on 2018/12/30.
//  Copyright © 2018 徐凯. All rights reserved.
//

#import "ViewController.h"
#import "Student.h"
#import <objc/runtime.h>
#import "NSObject+KVO.h"
@interface ViewController (){
    NSInteger index ;
}
@property(nonatomic,strong) Student* stu;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    index = 0;
    _stu = [Student new];
    NSLog(@"beforeClass:%@", object_getClass(_stu));
    [_stu XK_addObserver:self forKeyPath:@"age" options:NSKeyValueObservingOptionNew context:nil];
    NSLog(@"afterClass:%@", object_getClass(_stu));
}

- (void)XK_observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
     NSLog(@"keyPath:%@",keyPath);
     NSLog(@"ofObject:%@",object);
     NSLog(@"change:%@",change);
     NSLog(@"afterClass:%@", object_getClass(_stu));
    
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    index = index + 1;
    _stu.age = index;
}

@end
